package com.tengju.support.domain.model.rule;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.time.format.DateTimeFormatter;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@Clazz")
public class InviteHintAction implements Action{

    private String hintDesc;

    private static final String HINT_DESC = "hintDesc";

    @JsonProperty(value = "@Clazz")
    String getClazz() {
        return this.getClass().getName();
    };

    public InviteHintAction(Map<String,String> map) {
        this.hintDesc = map.get(HINT_DESC);
    }

    @Override
    public Object execute(MetaInfo metaInfo) {
        if (!(metaInfo instanceof UpgradeHintMetaInfo) || StringUtils.isEmpty(hintDesc)) {
            return null;
        }
        UpgradeHintMetaInfo hintMetaInfo = (UpgradeHintMetaInfo) metaInfo;
        String inviteTime = hintMetaInfo.getInviteTime().format(DateTimeFormatter.ofPattern("MM月dd日"));
        return String.format(hintDesc,inviteTime);
    }
}
